import request from '@/hooks/utils/http'
import { AxiosPromise } from 'axios'

export class TaskService {
    /**
     * 查询待办列表
     * @param query
     * @returns {*}
     */
    static pageByTaskWait = (query: TaskQuery): AxiosPromise<FlowTaskVO[]> => {
        return request({
            url: '/workflow/task/pageByTaskWait',
            method: 'get',
            params: query
        });
    };

    /**
     * 查询已办列表
     * @param query
     * @returns {*}
     */
    static pageByTaskFinish = (query: TaskQuery): AxiosPromise<FlowTaskVO[]> => {
        return request({
            url: '/workflow/task/pageByTaskFinish',
            method: 'get',
            params: query
        });
    };

    /**
     * 查询当前用户的抄送列表
     * @param query
     * @returns {*}
     */
    static pageByTaskCopy = (query: TaskQuery): AxiosPromise<FlowTaskVO[]> => {
        return request({
            url: '/workflow/task/pageByTaskCopy',
            method: 'get',
            params: query
        });
    };

    /**
     * 当前租户所有待办任务
     * @param query
     * @returns {*}
     */
    static pageByAllTaskWait = (query: TaskQuery): AxiosPromise<FlowTaskVO[]> => {
        return request({
            url: '/workflow/task/pageByAllTaskWait',
            method: 'get',
            params: query
        });
    };

    /**
     * 当前租户所有已办任务
     * @param query
     * @returns {*}
     */
    static pageByAllTaskFinish = (query: TaskQuery): AxiosPromise<FlowTaskVO[]> => {
        return request({
            url: '/workflow/task/pageByAllTaskFinish',
            method: 'get',
            params: query
        });
    };

    /**
     * 启动流程
     * @param data
     * @returns {*}
     */
    static startWorkFlow = (data: object): any => {
        return request({
            url: '/workflow/task/startWorkFlow',
            method: 'post',
            data: data
        });
    };

    /**
     * 办理流程
     * @param data
     * @returns {*}
     */
    static completeTask = (data: object) => {
        return request({
            url: '/workflow/task/completeTask',
            method: 'post',
            data: data
        });
    };

    /**
     * 任务驳回
     * @param data
     * @returns {*}
     */
    static backProcess = (data: any): any => {
        return request({
            url: '/workflow/task/backProcess',
            method: 'post',
            data: data
        });
    };

    /**
     * 获取当前任务
     * @param taskId
     * @returns
     */
    static getTask = (taskId: string) => {
        return request({
            url: '/workflow/task/getTask/' + taskId,
            method: 'get'
        });
    };

    /**
     * 修改任务办理人
     * @param taskIdList
     * @param userId
     * @returns
     */
    static updateAssignee = (taskIdList: Array<string>, userId: string) => {
        return request({
            url: `/workflow/task/updateAssignee/${userId}`,
            method: 'put',
            data: taskIdList
        });
    };

    /**
     * 终止任务
     * @returns
     */
    static terminationTask = (data: any) => {
        return request({
            url: `/workflow/task/terminationTask`,
            method: 'post',
            data: data
        });
    };

    /**
     * 获取可驳回得任务节点
     * @returns
     */
    static getBackTaskNode = (definitionId: string, nodeCode: string) => {
        return request({
            url: `/workflow/task/getBackTaskNode/${definitionId}/${nodeCode}`,
            method: 'get'
        });
    };

    /**
     * 任务操作 操作类型，委派 delegateTask、转办 transferTask、加签 addSignature、减签 reductionSignature
     * @returns
     */
    static taskOperation = (data: TaskOperationBo, operation: string) => {
        return request({
            url: `/workflow/task/taskOperation/${operation}`,
            method: 'post',
            data: data
        });
    };

    /**
     * 获取当前任务办理人
     * @param taskId 任务id
     * @returns
     */
    static currentTaskAllUser = (taskId: string | number) => {
        return request({
            url: `/workflow/task/currentTaskAllUser/${taskId}`,
            method: 'get'
        });
    };

    /**
     * 获取下一节点写
     * @param data参数
     * @returns
     */
    static getNextNodeList = (data: any): any => {
        return request({
            url: '/workflow/task/getNextNodeList',
            method: 'post',
            data: data
        });
    };

}

export interface TaskQuery extends PageQuery {
    nodeName?: string;
    flowCode?: string;
    flowName?: string;
    createByIds?: string[] | number[];
}

export interface ParticipantVo {
    groupIds?: string[] | number[];
    candidate: string[] | number[];
    candidateName: string[];
    claim: boolean;
}
export interface FlowTaskVO {
    id: string | number;
    createTime?: Date;
    updateTime?: Date;
    tenantId?: string;
    definitionId?: string;
    instanceId: string;
    flowName: string;
    businessId: string;
    nodeCode: string;
    nodeName: string;
    flowCode: string;
    flowStatus: string;
    formCustom: string;
    formPath: string;
    nodeType: number;
    nodeRatio: string | number;
    version?: string;
    applyNode?: boolean;
    buttonList?: buttonList[];
}

export interface buttonList {
    code: string;
    show: boolean;
}
export interface VariableVo {
    key: string;
    value: string;
}

export interface TaskOperationBo {
    //委派/转办人的用户ID（必填，准对委派/转办人操作）
    userId?: string;
    //加签/减签人的用户ID列表（必填，针对加签/减签操作）
    userIds?: string[];
    //任务ID（必填）
    taskId: string | number;
    //意见或备注信息（可选）
    message?: string;
}
